#include "includes.h"

#include "vb_impl.h"

static VB_CONF_S g_VbConf = {0};

#define MPP_ALIGN(x, a)         (((x)+(a)-1)&~((a)-1))

int AHB_alloc(AHardwareBuffer **pOutBuffer, uint32_t u32BlockSize)
{
    u32BlockSize = MPP_ALIGN(u32BlockSize, 16);

#if 0
    //这里特殊处理一下width,height,format,后期修改系统源码对外提供一个
    AHardwareBuffer_Desc desc = {0};
    desc.width = 16; //16 align
    desc.height = MPP_ALIGN(u32BlockSize/(16*2), 2);
    desc.layers = 1;
    desc.format = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;//2 bytes per pixel
    desc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY;

    int ret = AHardwareBuffer_allocate(&desc, pOutBuffer);
#else

    AHardwareBuffer_Desc desc = {0};
    desc.width = u32BlockSize;
    desc.height = 1;
    desc.layers = 1;
    desc.format = AHARDWAREBUFFER_FORMAT_BLOB;
    desc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY;

    int ret = AHardwareBuffer_allocate(&desc, pOutBuffer);

#endif

    return HI_SUCCESS;
}

int AHB_free(AHardwareBuffer *pOutBuffer)
{
    assert(pOutBuffer != NULL);
    AHardwareBuffer_release(pOutBuffer);
    return HI_SUCCESS;
}

int AHB_IncRef(AHardwareBuffer *pOutBuffer)
{
    assert(pOutBuffer != NULL);
    AHardwareBuffer_acquire(pOutBuffer);
    return HI_SUCCESS;
}

int AHB_DecRef(AHardwareBuffer *pOutBuffer)
{
    assert(pOutBuffer != NULL);
    AHardwareBuffer_release(pOutBuffer);
    return HI_SUCCESS;
}

VB_POOL HI_MPI_VB_CreatePool(HI_U32 u32BlkSize,HI_U32 u32BlkCnt,const HI_CHAR *pcMmzName)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_DestroyPool(VB_POOL Pool)
{
    return HI_SUCCESS;
}

VB_BLK HI_MPI_VB_GetBlock(VB_POOL Pool, HI_U32 u32BlkSize,const HI_CHAR *pcMmzName)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_ReleaseBlock(VB_BLK Block)
{
    return HI_SUCCESS;
}

HI_U32 HI_MPI_VB_Handle2PhysAddr(VB_BLK Block)
{
    return HI_SUCCESS;
}

VB_POOL HI_MPI_VB_Handle2PoolId(VB_BLK Block)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_InquireUserCnt(VB_BLK Block)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_Init(HI_VOID)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_Exit(HI_VOID)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_SetConf(const VB_CONF_S *pstVbConf)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_GetConf(VB_CONF_S *pstVbConf)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_MmapPool(VB_POOL Pool)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_MunmapPool(VB_POOL Pool)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_GetBlkVirAddr(VB_POOL Pool, HI_U32 u32PhyAddr, HI_VOID **ppVirAddr)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_InitModCommPool(VB_UID_E enVbUid)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_ExitModCommPool(VB_UID_E enVbUid)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_SetModPoolConf(VB_UID_E enVbUid, const VB_CONF_S *pstVbConf)
{
    return HI_SUCCESS;
}

HI_S32 HI_MPI_VB_GetModPoolConf(VB_UID_E enVbUid, VB_CONF_S *pstVbConf)
{
    return HI_SUCCESS;
}

VB_POOL HI_MPI_VB_CreateVirtualVbPool(HI_U32 u32BlkCnt, const HI_CHAR *pcMmzName)
{
    return HI_SUCCESS;
}

VB_BLK HI_MPI_VB_AddBlock(VB_POOL Pool , HI_U32 u32PhyAddr, HI_U32 u32Size)
{
    return HI_SUCCESS;
}

